package cn.dujc.superkid.adapter.cup;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.dujc.superkid.R;
import cn.dujc.superkid.activities.CupVideoActivity;
import cn.dujc.superkid.adapter.VideoChapterAdapter;
import cn.dujc.superkid.bean.CupListResult;
import cn.dujc.superkid.bean.VideoListResult;

/**
 * Created by Administrator on 2018/10/17 0017.
 */

public class CupChapterAdapter extends RecyclerView.Adapter<CupChapterAdapter.MyViewHolder> {
    private Context mContext;
    private List<CupListResult.VideoBean> list;
    private String video_id;
    private String course_id;

    public CupChapterAdapter(List<CupListResult.VideoBean> list, Context mContext, String video_id, String course_id) {
        this.list = list;
        this.mContext = mContext;
        this.video_id = video_id;
        this.course_id = course_id;
    }


    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_chapter, parent, false);
        return new MyViewHolder(view);
    }


    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.lessonname.setText((position + 1) + "、" + list.get(position).getVideo_title());
        if ((list.get(position).getId()+"").equals(video_id)) {

            holder.lessonname.setTextColor(Color.rgb(0, 0, 0));
        }
        holder.mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent in = new Intent();
                in.setClass(mContext, CupVideoActivity.class);
                in.putExtra("video_id", list.get(position).getId()+"");
                in.putExtra("course_id", course_id);
                in.putExtra("is_learn", "2");
                in.putExtra("videoTitle",list.get(position).getVideo_title());
                mContext.startActivity(in);
                ((Activity)mContext).finish();
            }
        });
    }
    public int getItemCount() {
        return list.size();
    }
    class MyViewHolder extends RecyclerView.ViewHolder {
        private View mView;
        private TextView lessonname;
        public MyViewHolder(View itemView) {
            super(itemView);
            mView = itemView;
            lessonname = itemView.findViewById(R.id.lessonname);
        }
    }
}